package com.matt.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import com.matt.domain.mp.ParentUser;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;


/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2017/7/18
 * *******************************
 */
public interface AppUserRepository extends JpaRepository<ParentUser, String>, JpaSpecificationExecutor<ParentUser> {

    ParentUser getById(String id);

    ParentUser findByPhone(String phone);

    @Query(value = "SELECT u.* from users u left JOIN userchildren r on u.id = r.uid where r.cid = ?1 and u.phone = ?2 ",nativeQuery = true)
    ParentUser findByCidAndPhone(String cid, String phone);

    @Query(value = "SELECT u.* from users u left JOIN userchildren r on u.id = r.uid where r.cid = ?1 group by u.phone", nativeQuery = true)
    List<ParentUser> findAllByCid(String cid);
}
